/*
 * Copyright (c) 2005 -2008 Reliable Source, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Mozilla Public License v.1.1,
 * BSD, and Eclipse Public License v1.0 which accompanies this
 * distribution and is available at:
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 * 		http://www.opensource.org/licenses/bsd-license.php
 * 		http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * Contributors:
 *     IBM Corporation	     -  http://ibm.com
 *     	- initial API and implementation
 *
 *     patientos.org         - http://patientos.org
 *     	- domain and database persistence layer
 *
 *     Reliable Source, Inc. - http://reliablesource.org
 *     	- Symbiosys Application Framework,
 *     	- Symbiosys Application, Symbiosys Product
 *
 */
package org.reliablesource.symbiosys.workbench.tests.editors;

import org.eclipse.core.commands.IHandler;

import org.eclipse.jface.viewers.StructuredSelection;

import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.tests.harness.util.UITestCase;


/**
*
* AbstractSymbiosysEditorTest.java<br>
* Created on: Oct 20, 2006<p>
*
* @author Dennis Park
* <a href="mailto:denpark@cisco.com">denpark@cisco.com</a>
*
* @since 4.0
*
*/
abstract public class AbstractSymbiosysEditorTest extends UITestCase {
    protected IWorkbenchWindow fWindow;
    protected IWorkbenchPage fPage;
    protected StructuredSelection selection;
    protected Object device;
    protected IHandler handler;

    public AbstractSymbiosysEditorTest(String testName) {
        super(testName);
    }

    protected void doSetUp() throws Exception {
        super.doSetUp();
        fWindow = openTestWindow();
        fPage = fWindow.getActivePage();

        assertNotNull("TestCase.Setup.windowPage is Null", fPage);

        fPage.closeAllPerspectives(false, false);

        int nOpened = fPage.getOpenPerspectives().length;
        assertEquals(0, nOpened);

        fPage = fWindow.openPage(getPerspectiveId(), null);
    }

    @Override
    protected void doTearDown() throws Exception {
        handler = null;

        if (fPage != null) {
            fPage.closeAllPerspectives(false, false);

            int nOpened = fPage.getOpenPerspectives().length;
            assertEquals("TestCase.tearDown.windowPage.Perspectives opened > 0",
                0, nOpened);
        }

        fPage.close();
        closeAllPages(fWindow);
        closeAllTestWindows();
        super.doTearDown();
    }

    abstract protected String getPerspectiveId();
}
